/****************************************************************************/
/*	File:		M4ViComAPI.h												*/
/*	Author:		Marc Legrand			       								*/
/*	email:		marc.legrand@philips.com									*/
/*	Org:		Philips Digital Networks - MP4Net							*/
/*	Created:	09/11/2000	           										*/
/*	Purpose:	Common definitions and structures of the Video Codec API	*/
/*	Notes:		MPEG-4 video codec API specifications 1.0					*/
/*	Status:		Under development		           							*/
/*	Modified:																*/
/*																			*/
/*	Copyright (C) 	Royal Philips Electronics								*/
/*					2000. All rights reserved								*/
/*									   										*/
/****************************************************************************/

#ifndef M4VICOM_H
#define M4VICOM_H

#ifdef __cplusplus

extern "C" {
#endif

/*################################
	Enumerated type definitions
#################################*/

/************************************************/
/*	CPU types definition						*/
/************************************************/
enum M4V_CPUTypes{
	M4V_CPU_TYPE_UNKNOWN,
	M4V_CPU_TYPE_386,
	M4V_CPU_TYPE_486,
	M4V_CPU_TYPE_PI,
	M4V_CPU_TYPE_PMMX,
	M4V_CPU_TYPE_PPRO,
	M4V_CPU_TYPE_PII,
	M4V_CPU_TYPE_PIII,
	M4V_CPU_TYPE_PIV
};
typedef enum M4V_CPUTypes M4V_CPU_TYPE;

/************************************************/
/*	formats definition							*/
/************************************************/
enum M4V_ColourFormats{
	M4V_YUV420_PLANAR = 0,
	M4V_YUV420_PACKET,
	M4V_AYUV4420,
	M4V_YUV422,
	M4V_AYUV4422,
	M4V_RGB32,
	M4V_ARGB32,
	M4V_RGB24,
	M4V_ARGB24,
	M4V_RGB565,
	M4V_ARGB565,
	M4V_RGB555,
	M4V_ARGB555,
	M4V_BGR32,
	M4V_BGR24
};
typedef enum M4V_ColourFormats M4V_COLOUR_FORMAT;

/************************************************/
/*	shape modes definition						*/
/************************************************/
enum M4V_ShapeModes{
	M4V_RECTANGULAR_SHAPE = 0,							/* Rectangular object */
	M4V_BINARY_SHAPE,								/* Arbitrary shaped object */
	M4V_GRAYSCALE_SHAPE,							/* Gray-level shaped object */	
	M4V_BINARY_ONLY_SHAPE							/* Arbitrary shaped object  without any texture information */
};
typedef enum M4V_ShapeModes M4V_SHAPE_MODE;

/************************************************/
/*	layer types definition						*/
/************************************************/
enum M4V_ViComLayerTypes{
	M4V_BASE_LAYER = 0,									/* Base layer type */
	M4V_TEMPORAL_EHN_LAYER							/* Enhancement layer type */
};
typedef enum M4V_ViComLayerTypes M4V_LAYER_TYPE;

/************************************************/
/*	aspect ratio definition						*/
/************************************************/
enum M4V_ViComAspectRatio{
	M4V_ASPECT_RATIO_1_1   = 0x01,
	M4V_ASPECT_RATIO_12_11 = 0x02,
	M4V_ASPECT_RATIO_10_11 = 0x03,
	M4V_ASPECT_RATIO_16_11 = 0x04,
	M4V_ASPECT_RATIO_40_33 = 0x05,
	M4V_ASPECT_RATIO_EXTENDED = 0x0f
};
typedef enum M4V_ViComAspectRatio M4V_ASPECT_RATIO;

/************************************************/
/*	MPEG-4 video profile and level definition	*/
/************************************************/
enum M4V_ViComProfileLevel{
	M4V_SIMPLE_LEVEL_0			= 0x10,
	M4V_SIMPLE_LEVEL_1			= 0x01,
	M4V_SIMPLE_LEVEL_2			= 0x02,
	M4V_SIMPLE_LEVEL_3			= 0x03,
	M4V_SIMPLE_SCALABLE_LEVEL_1	= 0x11,
	M4V_SIMPLE_SCALABLE_LEVEL_2	= 0x12,
	M4V_CORE_LEVEL_1			= 0x21,
	M4V_CORE_LEVEL_2			= 0x22,
	M4V_ADVANCED_SIMPLE_LEVEL_0	= 0xf1,
	M4V_ADVANCED_SIMPLE_LEVEL_1	= 0xf2,
	M4V_ADVANCED_SIMPLE_LEVEL_2	= 0xf3,
	M4V_ADVANCED_SIMPLE_LEVEL_3	= 0xf4
};
typedef enum M4V_ViComProfileLevel	M4V_PROFILE_LEVEL;


/************************************************/
/* types declarations							*/
/************************************************/
typedef unsigned char 	M4ViComU8;
typedef char 			M4ViComS8;
typedef unsigned short 	M4ViComU16;
typedef unsigned long	M4ViComU32;
typedef short 			M4ViComS16;
typedef long			M4ViComS32;
typedef float			M4ViComFloat;
typedef double			M4ViComDouble;
typedef unsigned char	M4ViComBoolean;
typedef unsigned char	M4ViComDataAddress;

/********************************/
/*	id definition				*/
/********************************/
typedef unsigned long	M4ViComHandleInstance;

/************************************************/
/*	error codes definition						*/
/************************************************/
#define	    M4V_OK						0			
#define		M4V_ERR						1		
#define		M4V_EXSY					2			
#define		M4V_ALLOCATE_FAILED 		3			
#define		M4V_REGISTRATION_FAILED		4			
#define		M4V_INVALID_ID				5			
#define		M4V_ERR_PARAM				6	
#define		M4V_NOT_IMPLEMENTED			7	
#define		M4V_NO_NEW_IMAGE			8	
#define		M4V_PROCESSAU_FAILED		9
#define     M4V_SPECIFIC_ERROR          10

typedef M4ViComU32 M4ViComErrorCode;

/************************************************/
/*	software release information				*/
/************************************************/
typedef struct
{
  M4ViComU8	software_major_number;			/* Major Release number of the library. */
  M4ViComU8	software_minor_number;				/* Minor release number of the library. */
  M4ViComU8	software_revision_number;				/* Patch revision number of the library. */
} M4ViComVersion;

/************************************************************/
/* aspect ratio structure									*/
/* parameters in this structure give the pixel aspect ratio */
/* as encoded in the bitstream								*/
/************************************************************/
typedef struct
{
	M4ViComU32				par_width;				/* 	*/
	M4ViComU32				par_height;				/*  */
	M4V_ASPECT_RATIO		aspect_ratio;			/* pixel aspect ratio */
} M4ViComPARinfo;

/************************************************************/
/* video fragment structure.								*/
/* This structure is used to describe and contain one video	*/
/* fragment (vp) of an AU at the input.						*/
/************************************************************/
typedef struct
{
	M4ViComU32 first_size;		/*size in bits of the first partition if data partitionning, 
								size of the fragment otherwise. must be 0 if missing*/
	M4ViComU32 second_size;		/*size in bits of the second partition if data partitionning, 0 otherwise*/
	M4ViComU32 frag_info;		/*info about the fagment. See below*/
	M4ViComU8	*data;			/*pointer on the data of the current fragment. 
								NB : ALL AVALAIBLE FRAGMENTS ARE CONCATENETED IN THE AU SAME BUFFER*/
} M4ViDecVideoFrag;

/****************************************************************************************/
/* Info on the video fragment.															*/
/* Used in the field frag_info inside the M4ViDecVideoFrag structure.					*/
/****************************************************************************************/
enum M4V_FragmentInfo{
	M4V_FRAGMENT_OK,			/*The fragment is good*/
	M4V_FRAGMENT_MISSING,		/*The fragment is missing*/
	M4V_FRAGMENT_CORRUPTED		/*The fragment appears to be corrupted*/
};
typedef enum M4V_FragmentInfo M4V_FRAGMENT_INFO;

/************************************************************/
/* AU structure at the input.								*/
/* This structure is used when calling the call-back		*/
/* function M4ViDEC_StreamHandler_get_video_data when		*/
/* waiting for a new AU to decode. It contains all usefull	*/
/* info about the AU, and pointers on the data.				*/
/************************************************************/
typedef struct
{
	M4ViComU32 cts;					/*cts of the current AU*/
	M4ViComU32 dts;					/*dts of the current AU*/
	M4ViComU32 nb_fragments;			/*number of fragments in this AU (vp)*/
	M4ViDecVideoFrag *video_fragment;	/*pointer on video fragment structures. One by vp*/
} M4ViDecEncodedData;

/************************************************/
/*		 Image Plane							*/
/************************************************/
typedef	struct	
{
	M4ViComU32		u_width;			/* active width, in pixels */
	M4ViComU32		u_height;			/* active height, in lines */
	M4ViComU32		u_topleft;			/* index of 1st active pixel */
	M4ViComU32		u_stride;			/* line stride, in bytes */	
	M4ViComU8		*pac_data;			/* buffer address */
}	M4ViComImagePlane;

/****************************************************/
/*		     Allocations/De-allocations functions	*/
/****************************************************/

/* these fucntions are defined as external and must be implemented */
/* by the application encapsulating the library */
void *M4VAllocateMemory (unsigned long Size,unsigned long NumberOfElements,unsigned long KindOf);
void M4VFreeMemory (void *pointer);


/****************************************************/
/*		     Allocations type IDs					*/
/****************************************************/

#define	    M4V_COM_DEFAULT					0x0		/* ID by default for all codec allocations in common part */				
#define	    M4V_COM_DCTPRED_ARRAY			0x1		/* ID for DCT predictor tables */	
#define	    M4V_COM_Q_ARRAY					0x2		/* ID for quantizer tables */		
#define	    M4V_COM_VOP_STRUCT				0x3		/* ID for M4ViComVop structure */			
#define	    M4V_COM_DPOOL_STRUCT			0x4		/* ID for DPool structure */			

#define	    M4V_ENC_DEFAULT					0x100	/* ID by default for all encoder allocations */		
#define	    M4V_ENC_SEQ_STRUCT				0x101	/* ID for M4ViEncSequence structure */					
#define	    M4V_ENC_VOP_PLANEY				0x102	/* ID for Y Vop texture plane */					
#define	    M4V_ENC_VOP_PLANEUV				0x103	/* ID for U or V Vop texture plane */				
#define	    M4V_ENC_REGUL_STRUCT			0x104	/* ID for regulation structures */
#define	    M4V_ENC_FRAME_STRUCT			0x105	/* ID for M4ViEncInFrame structure */
#define	    M4V_ENC_FRAME_PLANEY			0x106	/* ID for Y frame texture plane */				
#define	    M4V_ENC_FRAME_PLANEUV			0x107	/* ID for U or Vframe texture plane */				
#define	    M4V_ENC_REGULHIST_ARRAY			0x108	/* ID for regulation history data */
#define	    M4V_ENC_MBDESC_ARRAY			0x109	/* ID for mb descriptors */	
#define	    M4V_ENC_MV_ARRAY				0x10A	/* ID for motion vectors */	
#define	    M4V_ENC_MVVECT_ARRAY			0x10B	/* ID for motion vectors */	
#define	    M4V_ENC_MBENC_STRUCT			0x10C	/* ID for encoded macroblock structure */	
#define	    M4V_ENC_ESTMBDATA_STRUCT		0x10D	/* ID for param block for EstMotMbText3DRS */
#define	    M4V_ENC_RECONS_STRUCT			0x10E	/* ID for structure for prediction storage */
#define	    M4V_ENC_ENCVOP_STRUCT			0x10F	/* ID for M4ViEncEncoderVop structure */
#define	    M4V_ENC_SAD_ARRAY				0x110	/* ID for sad array*/
#define	    M4V_ENC_HAD_ARRAY				0x111	/* ID for hadamard arrays */
#define	    M4V_ENC_MBAGE_ARRAY				0x112	/* ID for MB age array (intra refresh) */
#define	    M4V_ENC_DPART_BUF				0x113	/* ID for streams buffer in case of data partitionning */

#define	    M4V_DEC_DEFAULT					0x200	/* ID by default for all decoder allocations */				
#define	    M4V_DEC_VOL_STRUCT				0x201	/* ID for M4ViComVol structure */			
#define	    M4V_DEC_VOP_PLANEY				0x202	/* ID for Y Vop texture plane */					
#define	    M4V_DEC_VOP_PLANEUV				0x203	/* ID for U or V Vop texture plane */				
#define	    M4V_DEC_BS_STRUCT				0x204	/* ID for M4ViComBitstream structure */			
#define	    M4V_DEC_RECONST_BUF				0x205	/* ID for reconstruction buffer in case of one vop use */				
#define	    M4V_DEC_MBDESC_ARRAY			0x206	/* ID for mb descriptors */	
#define	    M4V_DEC_MV_ARRAY				0x207	/* ID for motion vectors */	
#define	    M4V_DEC_MBSTAT_ARRAY			0x208	/* ID for mb error status */	
#define	    M4V_DEC_DPART_ARRAY				0x209	/* ID for mb data partionning info */	
#define	    M4V_DEC_DEBLOCK_ARRAY			0x20A	/* ID for mb info (deblocking filter) */	



/************************************************/
/*		     Color of Background				*/
/************************************************/

typedef M4ViComErrorCode (*p_M4VOutputFilter)(void *user_data, M4ViComImagePlane* in, M4ViComImagePlane* out);

typedef	struct
{
	M4ViComU8 Y;
	M4ViComU8 U;
	M4ViComU8 V;
	M4ViComU8 reserved;
}M4ViComBackgroundColor;


#ifdef __cplusplus
}
#endif


#endif			/* end of file */

